cmake_minimum_required(VERSION 3.0 FATAL_ERROR)
project(example-app)
set(CMAKE_CXX_STANDARD 14)
 set(CMAKE_RUNTIME_OUTPUT_DIRECTORY "${CMAKE_BINARY_DIR}/bin/")
 message(STATUS "CMAKE_CURRENT_SOURCE_DIR:" ${CMAKE_CURRENT_SOURCE_DIR} )
 message(STATUS "OUTPUT_DIRECTORY:" ${CMAKE_BINARY_DIR}/bin/ )
set(OpenCV_DIR /opt/opencv-4.5.3/build_c++14/)
#add_definitions(-D_GLIBCXX_USE_CXX11_ABI=0)
find_package(Torch REQUIRED)
find_package(OpenCV 4 REQUIRED)
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} ${TORCH_CXX_FLAGS}")
message(STATUS "OPENCV_INSTALLPATH:" ${OpenCV_INSTALL_PATH} )
include_directories( ${OpenCV_INCLUDE_DIRS} )


 
add_executable(example-app example-app.cpp)
include_directories( ${OpenCV_INCLUDE_DIRS} )
add_executable(cxx_simple.out cxx_simple.cpp)
add_executable(cxx_inference.out cxx_inference.cpp)
add_executable(cpp_resnet.out cpp_resnet.cpp)
 add_executable(checkCUDA.out checkCUDA.cpp)
 add_executable(cpp_resnetGPU.out cpp_resnetGPU.cpp)
 
 target_link_libraries(cpp_resnetGPU.out ${OpenCV_LIBS} "${TORCH_LIBRARIES}")
target_link_libraries(example-app "${TORCH_LIBRARIES}")
target_link_libraries(cxx_simple.out ${OpenCV_LIBS} "${TORCH_LIBRARIES}"  )
target_link_libraries(cxx_inference.out  ${OpenCV_LIBS} "${TORCH_LIBRARIES}")
target_link_libraries(cpp_resnet.out ${OpenCV_LIBS} "${TORCH_LIBRARIES}")
target_link_libraries(checkCUDA.out ${OpenCV_LIBS} "${TORCH_LIBRARIES}")
set_property(TARGET example-app PROPERTY CXX_STANDARD 14)
set_property(TARGET cxx_inference.out PROPERTY CXX_STANDARD 14)
set_property(TARGET cpp_resnet.out PROPERTY CXX_STANDARD 14)
# The following code block is suggested to be used on Windows.
# According to https://github.com/pytorch/pytorch/issues/25457,
# the DLLs need to be copied to avoid memory errors.
if (MSVC)
  file(GLOB TORCH_DLLS "${TORCH_INSTALL_PREFIX}/lib/*.dll")
  add_custom_command(TARGET example-app
                     POST_BUILD
                     COMMAND ${CMAKE_COMMAND} -E copy_if_different
                     ${TORCH_DLLS}
                     $<TARGET_FILE_DIR:example-app>)
endif (MSVC)






